import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;

public class SongBits {

	static ArrayList<Float> ALL_MEANS;

	private int bitString;

	public SongBits(ResultSet song) {
		// remember field zero is at the end (LSB)

		try {
			setBits(song);
			//System.out.println( Integer.toHexString(bitString));
		} catch (SQLException e) {
			e.printStackTrace();
		}

	}

	static void setMeans(ArrayList<Float> means) {
		ALL_MEANS = new ArrayList<Float>();
		ALL_MEANS = means;
	}
	
	private void setNthBit(int n)
	{
		int setter = 1 << n;
		bitString = bitString | setter;
	}
	
	private void setBits(ResultSet song) throws SQLException {
		bitString = 0x00000000;

		float artistFamiliarity;
		float artistHotness;
		float duration;
		float loudness;
		float songHotness;
		float tempo;
		int year;
		
		artistFamiliarity = song.getFloat("ArtistFamilarity");
		artistHotness = song.getFloat("ArtistHotness");
		duration = song.getFloat("Duration");
		loudness = song.getFloat("Loudness");
		songHotness = song.getFloat("SongHotness");
		tempo = song.getFloat("Tempo");
		year = song.getInt("Year");
		
		if (artistFamiliarity > ALL_MEANS.get(0)) {
			setNthBit(0);
		}
		if (artistHotness > ALL_MEANS.get(1)) {
			setNthBit(1);
		}
		if (duration > ALL_MEANS.get(2)) {
			setNthBit(2);
		}
		if (loudness > ALL_MEANS.get(3)) {
			setNthBit(3);
		}
		if (songHotness > ALL_MEANS.get(4)) {
			setNthBit(4);
		}
		if (tempo > ALL_MEANS.get(5)) {
			setNthBit(5);
		}
		if (year > ALL_MEANS.get(6)) {
			setNthBit(6);
		}
	}
	
	public int getBits()
	{
		return this.bitString;
	}
}
